package com.qo;

import lombok.*;

import java.util.List;

@NoArgsConstructor
@ToString
@AllArgsConstructor
@Getter
@Setter
//封装分页页面显示数据类
public class PageResult<T> {
    //用户传递
    //当前页
    private Integer currentPage;
    //每页显示的条数
    private Integer pageSize;
    //数据库查询获取
    //满足分页显示的数据总条数
    private Integer totalCount;
    //满足分页显示的所有数据
    private List<T> data;
    //后台计算
    //总页数
    private Integer totalPage;
    //上一页
    private Integer prevPage;
    //下一页
    private Integer nextPage;

    //自定义有参构造器,实习总页数,上一页,下一页的计算
    public PageResult(Integer currentPage, Integer pageSize, Integer totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;
        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1 : 1;
        this.nextPage = this.currentPage + 1 <= this.totalPage ?
                this.currentPage + 1 : this.totalPage;
    }
}
